package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class HJ38_寻找关键钥匙 {
  public static void main(String[] args) throws FileNotFoundException {
    Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/38.txt"));
    String s = in.nextLine();
    String s2 = in.nextLine();
    String[] sArray = s2.substring(2).split(" ");
    Set<Character> set1 = new HashSet<>();
    for (Character a : s.toCharArray()) {
      if (Character.isAlphabetic(a)) {
        set1.add(Character.toLowerCase(a));
      }
    }
    for (int i = 0; i < sArray.length; i++) {
      Set<Character> set2 = new HashSet<>();
      for (Character a : sArray[i].toCharArray()) {
        if (Character.isAlphabetic(a)) {
          set2.add(Character.toLowerCase(a));
        }
      }
      if (set2.equals(set1)) {
        System.out.println(i + 1);
        return;
      }
    }
    System.out.println(-1);
  }
}
